package gameloft.eggcatcher;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.MouseInfo;
import java.awt.Rectangle;

import javax.swing.ImageIcon;


public class Egg extends Product {

	Egg(int x_ani) {
		super(x_ani);
		switch(rand.nextInt(3))
		{
		case 0:
			imgproduct = new ImageIcon("resource\\images\\egg.png").getImage();
			break;
		case 1:
			imgproduct = new ImageIcon("resource\\images\\egg1.png").getImage();
			break;
		case 2:
			imgproduct = new ImageIcon("resource\\images\\egg2.png").getImage();
			break;
		case 3:
			imgproduct = new ImageIcon("resource\\images\\egg3.png").getImage();
			break;
		}
	}
	@Override
	public boolean detectCollision(Basket basket, Player player, int x_ani) {
		Rectangle basketRect = new Rectangle(basket.x_basket,basket.y_basket,70,45); 
		Rectangle eggRect    = new Rectangle(productX,productY,50,60); 
		
		if(eggRect.intersects(basketRect))
		{
			player.score++;
			return true;
		}
		else
			return false;
	}

	@Override
	public boolean Check(Basket basket, Player player, int x_ani) {
		minfo = MouseInfo.getPointerInfo();
		point = minfo.getLocation();
		basket.followMouse((int)point.getX() -100);
		//
		if(!(detectCollision(basket,player,x_ani))) // kiểm tra va chạm)
		{
			if(productY >=650)
			{
				player.eggbreak++;
				return true;
			}
			else
			{
				productY++;
				return false;
			}
		}
		return true;
	}
}
